package com.sts.controller;

import com.sts.common.result.Result;
import com.sts.dto.NotificationCreateDTO;
import com.sts.dto.NotificationDTO;
import com.sts.service.NotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notification")
@RequiredArgsConstructor
public class NotificationController {

    private final NotificationService notificationService;

    /** 创建通知（内部调用或管理员） */
    @PostMapping
    public Result<Long> create(@RequestBody NotificationCreateDTO dto) {
        return Result.success(notificationService.create(dto));
    }

    /** 当前用户未读通知 */
    @GetMapping("/unread")
    public Result<List<NotificationDTO>> unread(@RequestHeader("X-User-Id") Long receiverId) {
        return Result.success(notificationService.listUnread(receiverId));
    }

    /** 当前用户全部通知 */
    @GetMapping("/all")
    public Result<List<NotificationDTO>> all(@RequestHeader("X-User-Id") Long receiverId) {
        return Result.success(notificationService.listAll(receiverId));
    }

    /** 标记单条已读 */
    @PutMapping("/{id}/read")
    public Result<Void> markRead(@PathVariable Long id,
                                 @RequestHeader("X-User-Id") Long receiverId) {
        notificationService.markRead(id, receiverId);
        return Result.success();
    }

    /** 全部已读 */
    @PutMapping("/read-all")
    public Result<Void> markAllRead(@RequestHeader("X-User-Id") Long receiverId) {
        notificationService.markAllRead(receiverId);
        return Result.success();
    }
}